package case_library_backup

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/case_library_backup"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	case_library_backupReq "github.com/flipped-aurora/gin-vue-admin/server/model/case_library_backup/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "github.com/flipped-aurora/gin-vue-admin/server/utils"
)

type Case_struct_backupApi struct {
}

var case_backupService = service.ServiceGroupApp.Case_library_backupServiceGroup.Case_struct_backupService


// CreateCase_struct_backup 创建Case_struct_backup
// @Tags Case_struct_backup
// @Summary 创建Case_struct_backup
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body case_library_backup.Case_struct_backup true "创建Case_struct_backup"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /case_backup/createCase_struct_backup [post]
func (case_backupApi *Case_struct_backupApi) CreateCase_struct_backup(c *gin.Context) {
	var case_backup case_library_backup.Case_struct_backup
	err := c.ShouldBindJSON(&case_backup)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    verify := utils.Rules{
        "Manufacturing_serial_number":{utils.NotEmpty()},
        "Troubleshooting_date":{utils.NotEmpty()},
        "Process_design_document_number":{utils.NotEmpty()},
        "Responsible_craftman":{utils.NotEmpty()},
        "Fault_description":{utils.NotEmpty()},
        "Ata_chapter_level1":{utils.NotEmpty()},
        "Ata_chapter_level2":{utils.NotEmpty()},
    }
	if err := utils.Verify(case_backup, verify); err != nil {
    		response.FailWithMessage(err.Error(), c)
    		return
    	}
	if err := case_backupService.CreateCase_struct_backup(&case_backup); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteCase_struct_backup 删除Case_struct_backup
// @Tags Case_struct_backup
// @Summary 删除Case_struct_backup
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body case_library_backup.Case_struct_backup true "删除Case_struct_backup"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /case_backup/deleteCase_struct_backup [delete]
func (case_backupApi *Case_struct_backupApi) DeleteCase_struct_backup(c *gin.Context) {
	var case_backup case_library_backup.Case_struct_backup
	err := c.ShouldBindJSON(&case_backup)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := case_backupService.DeleteCase_struct_backup(case_backup); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteCase_struct_backupByIds 批量删除Case_struct_backup
// @Tags Case_struct_backup
// @Summary 批量删除Case_struct_backup
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Case_struct_backup"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /case_backup/deleteCase_struct_backupByIds [delete]
func (case_backupApi *Case_struct_backupApi) DeleteCase_struct_backupByIds(c *gin.Context) {
	var IDS request.IdsReq
    err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := case_backupService.DeleteCase_struct_backupByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateCase_struct_backup 更新Case_struct_backup
// @Tags Case_struct_backup
// @Summary 更新Case_struct_backup
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body case_library_backup.Case_struct_backup true "更新Case_struct_backup"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /case_backup/updateCase_struct_backup [put]
func (case_backupApi *Case_struct_backupApi) UpdateCase_struct_backup(c *gin.Context) {
	var case_backup case_library_backup.Case_struct_backup
	err := c.ShouldBindJSON(&case_backup)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
      verify := utils.Rules{
          "Manufacturing_serial_number":{utils.NotEmpty()},
          "Troubleshooting_date":{utils.NotEmpty()},
          "Process_design_document_number":{utils.NotEmpty()},
          "Responsible_craftman":{utils.NotEmpty()},
          "Fault_description":{utils.NotEmpty()},
          "Ata_chapter_level1":{utils.NotEmpty()},
          "Ata_chapter_level2":{utils.NotEmpty()},
      }
    if err := utils.Verify(case_backup, verify); err != nil {
      	response.FailWithMessage(err.Error(), c)
      	return
     }
	if err := case_backupService.UpdateCase_struct_backup(case_backup); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindCase_struct_backup 用id查询Case_struct_backup
// @Tags Case_struct_backup
// @Summary 用id查询Case_struct_backup
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query case_library_backup.Case_struct_backup true "用id查询Case_struct_backup"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /case_backup/findCase_struct_backup [get]
func (case_backupApi *Case_struct_backupApi) FindCase_struct_backup(c *gin.Context) {
	var case_backup case_library_backup.Case_struct_backup
	err := c.ShouldBindQuery(&case_backup)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if recase_backup, err := case_backupService.GetCase_struct_backup(case_backup.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"recase_backup": recase_backup}, c)
	}
}

// GetCase_struct_backupList 分页获取Case_struct_backup列表
// @Tags Case_struct_backup
// @Summary 分页获取Case_struct_backup列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query case_library_backupReq.Case_struct_backupSearch true "分页获取Case_struct_backup列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /case_backup/getCase_struct_backupList [get]
func (case_backupApi *Case_struct_backupApi) GetCase_struct_backupList(c *gin.Context) {
	var pageInfo case_library_backupReq.Case_struct_backupSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := case_backupService.GetCase_struct_backupInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
